Skip to content

feat: xev Dynamic API + gitignore updates for Shadow support#704

Merged
g11tech merged 3 commits intomainfrom
shadow-to-main
Apr 8, 2026
Merged

feat: xev Dynamic API + gitignore updates for Shadow support#704
g11tech merged 3 commits intomainfrom
shadow-to-main

Conversation

@GrapeBaBa
Copy link
Copy Markdown
Member

Summary

  • Switch xev from compile-time backend selection to Dynamic API for runtime io_uring/epoll detection
  • This makes the binary portable across Linux kernel versions and Shadow-compatible
  • Add gitignore entries for zig-pkg/ cache, Shadow simulator outputs, and IDE files

Details

xev Dynamic API

All @import("xev") changed to @import("xev").Dynamic, which probes io_uring at runtime and falls back to epoll. A detectBackend() helper in utils.zig is called early in main and in test setup.

gitignore

  • zig-pkg/ — local Zig package cache (should not be committed)
  • shadow.yaml, shadow.data/ — generated by lean-quickstart/run-shadow.sh
  • .idea/ — JetBrains IDE files

Test plan

  • Verify build passes on CI
  • Verify existing tests pass
  • Verify Shadow 4-node devnet works with lean-quickstart/run-shadow.sh

Copilot AI review requested due to automatic review settings April 2, 2026 14:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Zig codebase to use libxev’s Dynamic API so the runtime can select the best available I/O backend (io_uring vs epoll), improving portability across Linux kernel versions and compatibility with Shadow. It also updates .gitignore to exclude additional local/tool-generated artifacts.

Changes:

  • Switched @import("xev") usages to @import("xev").Dynamic across node, network, and CLI code.
  • Added a detectBackend() helper and invoked it early in CLI startup and node test initialization.
  • Updated .gitignore to ignore zig-pkg/, Shadow outputs, and .idea/.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkgs/node/src/utils.zig Introduces detectBackend() and moves node code to xev.Dynamic.
pkgs/node/src/testing.zig Calls backend detection before initializing the event loop in tests.
pkgs/node/src/node.zig Switches xev import for tests to xev.Dynamic.
pkgs/node/src/lib.zig Re-exports detectBackend for external callers (CLI).
pkgs/node/src/clock.zig Switches xev import to xev.Dynamic.
pkgs/network/src/mock.zig Switches to xev.Dynamic and adds backend detection in tests.
pkgs/network/src/interface.zig Switches xev import to xev.Dynamic.
pkgs/network/src/ethlibp2p.zig Switches xev import to xev.Dynamic.
pkgs/cli/src/node.zig Switches xev import to xev.Dynamic.
pkgs/cli/src/main.zig Calls node_lib.detectBackend() early during CLI startup.
build.zig Notes that xev backend override is no longer needed.
.gitignore Ignores zig-pkg/, Shadow outputs, and JetBrains IDE files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 777 to 778
if (@hasDecl(xev, "detect")) xev.detect() catch @panic("no available xev backend");
var loop = try xev.Loop.init(.{});
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if (@hasDecl(xev, "detect")) xev.detect() ... backend-detection snippet is duplicated in multiple tests in this file. Consider factoring it into a small local helper (e.g., detectBackendOrPanic()), so the behavior/error handling stays consistent and future changes only need to be made once.

Copilot uses AI. Check for mistakes.
Comment on lines 958 to 960
if (@hasDecl(xev, "detect")) xev.detect() catch @panic("no available xev backend");
var loop = try xev.Loop.init(.{});
defer loop.deinit();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This backend detection line duplicates the same xev.detect() snippet used earlier in this file. To reduce repetition (and keep the panic/error message consistent), consider extracting the detection into a single helper and calling it from each test before xev.Loop.init.

Copilot uses AI. Check for mistakes.
Switch from compile-time xev backend selection to the Dynamic API,
which probes io_uring at runtime and falls back to epoll. This is
needed for Shadow network simulator (no io_uring support) but also
makes the binary portable across Linux kernel versions.
zclawz

This comment was marked as duplicate.

@g11tech
Copy link
Copy Markdown
Member

g11tech commented Apr 7, 2026

copilot suggestions seem appropriate, can you apply them/resolve them

- Change detectBackend() to return error instead of panicking, so
  callers get the underlying error name for debugging
- Update CLI main.zig to handle the error via ErrorHandler
- Update testing.zig to propagate the error
- Extract detectBackendOrFail() helper in mock.zig to eliminate
  duplicated xev.detect() snippets
Copilot AI review requested due to automatic review settings April 8, 2026 12:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GrapeBaBa GrapeBaBa requested review from Copilot and zclawz April 8, 2026 13:00
@GrapeBaBa
Copy link
Copy Markdown
Member Author

copilot suggestions seem appropriate, can you apply them/resolve them

fixed

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 49 to +54
pub fn init(allocator: Allocator, opts: NodeTestOptions) !NodeTestContext {
const utils = @import("./utils.zig");
utils.detectBackend() catch |err| {
std.log.err("failed to detect I/O backend: {s}", .{@errorName(err)});
return err;
};
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@import("./utils.zig") is being done inside NodeTestContext.init. In this codebase, file/module imports are typically declared at top-level with the other const ... = @import(...) statements; consider moving this to a top-level const utils = @import("./utils.zig"); to keep imports centralized and avoid function-local compile-time imports.

Copilot uses AI. Check for mistakes.
Comment on lines +754 to +760
/// Detect the best available I/O backend at runtime.
/// Factored out to avoid duplicating the detection snippet in every test.
fn detectBackendOrFail() !void {
if (@hasDecl(xev, "detect")) {
try xev.detect();
}
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detectBackendOrFail() duplicates the backend-detection logic introduced in pkgs/node/src/utils.zig (and now exported as @zeam/node.detectBackend). To avoid the two implementations drifting if libxev’s Dynamic API changes, consider centralizing this helper in a shared place (e.g. @zeam/utils) and calling it from both node and network tests.

Copilot uses AI. Check for mistakes.
Comment on lines +1416 to 1417
const xev = @import("xev").Dynamic;

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This xev import appears unused in this file (no xev. references). If it’s not needed anymore, it should be removed to reduce confusion about where the event loop backend is configured.

Suggested change
const xev = @import("xev").Dynamic;

Copilot uses AI. Check for mistakes.
@g11tech g11tech merged commit 4b2a711 into main Apr 8, 2026
20 checks passed
@g11tech g11tech deleted the shadow-to-main branch April 8, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants